﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using HtmlAgilityPack;
using System.IO;
namespace TestProject
{
    class Program
    {
        private const string html = "<p><img width=\"130\" height=\"97\" alt=\"\" src=\"/blog/dosyalar/MakaleDosyalari/image/6769_1213952469377_...";

        static void Main(string[] args)
        {
            HtmlAgilityTest();
            Console.ReadLine();
        }

        private static void HtmlAgilityTest()
        {
            HtmlDocument doc = new HtmlDocument();
            doc.OptionCheckSyntax = true;
            doc.OptionAutoCloseOnEnd = true;
            doc.OptionFixNestedTags = true;
            doc.OptionOutputOptimizeAttributeValues = true;

            doc.LoadHtml(html);
            foreach (HtmlParseError err in doc.ParseErrors)
            {
                if (err.Code.Equals(HtmlParseErrorCode.TagNotClosed))
                {
                    //doc.DocumentNode.InnerHtml.Replace(err.SourceText, String.Empty);
                }
                Console.WriteLine(err.Reason);
            }

            var list = doc.DocumentNode.DescendantsAndSelf().Where(t => !t.Closed);
            for (int i = 0; i < list.Count(); i++)
            {
                (list.ElementAt(i) as HtmlNode).Remove();
            }

            Console.WriteLine(doc.DocumentNode.InnerHtml);
        }

        private static void ReflectionTest()
        {
            TestObject obj = new TestObject();
            obj.P1 = "V1";
            obj.P2 = "V2";

            object obj2 = obj;

            PropertyInfo pInfo = obj.GetType().GetProperty("P1");
            Console.WriteLine("{0}:{1}", pInfo.Name, pInfo.GetValue(obj2, null));
        }


    }

    class TestObject
    {
        public string P1 { get; set; }
        public string P2 { get; set; }
    }
}
